<template>
  <div class="app-container">

    <el-table
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
      />
      <el-table-column
        label="任务名称"
        prop="typeName"
        :show-overflow-tooltip="true"
        min-width="150"
      />
      <el-table-column
        label="说明"
        prop="roleId"
        :show-overflow-tooltip="true"
        min-width="150"
      />
      <el-table-column
        label="每日执行规则"
        prop="roleId"
        :show-overflow-tooltip="true"
        min-width="150"
      />
      <el-table-column
        label="上次执行时间"
        prop="roleId"
        :show-overflow-tooltip="true"
        min-width="150"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
          >编辑时间
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleManualExecution(scope.row)"
            v-hasPermi="['system:role:remove']"
          >手动执行
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="130px"
      >
        <el-form-item
          label="任务名称"
          prop="typeName"
        >
          <el-input
            v-model="form.typeName"
            placeholder="请输入账户名称"
          />
        </el-form-item>
        <el-form-item
          label="说明"
          prop="identifying"
        >
          <el-input
            v-model="form.identifying"
            placeholder="请输入账号"
          />
        </el-form-item>
        <el-form-item
          label="每日执行规则"
          prop="identifying"
        >
          <el-input
            v-model="form.identifying"
            placeholder="请输入开户行"
          />
        </el-form-item>
        <el-form-item
          label="上次执行时间"
          prop="identifying"
        >
          <el-input
            v-model="form.identifying"
            placeholder="请输入行号"
          />
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          type="primary"
          @click="submitForm"
        >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
  
<script>
import { listRole, getRole, addRole, updateRole, } from '@/api/system/role'

export default {
  name: 'scheduleTask',
  dicts: [],
  data() {
    return {
      // 遮罩层
      // loading: true,
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信调表格数据
      dataList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        typeName: [
          { required: true, message: '信调类别名称不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '适用客户不能为空', trigger: 'blur' }
        ],
        illustrate: [
          { required: true, message: '说明不能为空', trigger: 'blur' }
        ],
        indicatorIllustrate: [
          { required: true, message: '指标说明不能为空', trigger: 'blur' }
        ],
        identifying: [
          { required: true, message: '标识不能为空', trigger: 'blur' }
        ],
        uploadAnnex: [
          { required: true, message: '是否要求上传附件不能为空', trigger: 'blur' }
        ],
      }



    }
  },
  created() {
    //   this.getList()
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      }
      )
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([])
      }
      this.form = {
        roleId: undefined,
        roleName: undefined,
        status: '0',
      }
      this.resetForm('form')
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 编辑时间按钮操作 */
    handleUpdate(row) {
      this.reset()
      getRole(row.roleId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改角色'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.roleId != undefined) {
            updateRole(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addRole(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 手动执行按钮操作 */
    handleManualExecution(row) {
      // this.$modal.confirm('是否确认删除角色编号为"' + row.roleId + '"的数据项？').then(function() {
      //     return delRole(row.roleId)
      // }).then(() => {
      //     this.getList()
      //     this.$modal.msgSuccess('删除成功')
      // }).catch(() => {
      // })
    },


  }
}
</script>